package com.eaoa.query.bus;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import org.hibernate.Hibernate;
import org.hibernate.HibernateException;

import com.eaoa.base.EABaseQuery;
import com.eaoa.vo.bus.BusOrder;

public class BusOrderQuery extends EABaseQuery{
	
	boolean lazyInitPubCustomer = false;
	boolean lazyInitBusTransfer = false;
	boolean lazyInitBusCargos= false;

	public BusOrderQuery() {
		super(BusOrder.class);
	}
	
	public void setLazyInitPubCustomer(boolean lazyInitPubCustomer) {
		this.lazyInitPubCustomer = lazyInitPubCustomer;
	}
	public void setLazyInitBusTransfer(boolean lazyInitBusTransfer) {
		this.lazyInitBusTransfer = lazyInitBusTransfer;
	}
	public void setLazyInitBusCargos(boolean lazyInitBusCargos) {
		this.lazyInitBusCargos = lazyInitBusCargos;
	}

	protected void lazeInit() throws HibernateException {
		Iterator it = getResults().iterator();
		while (it.hasNext()) {
			BusOrder vo = (BusOrder) it.next();
			if (lazyInitPubCustomer) {
				Hibernate.initialize(vo.getPubCustomer());
			}
			if (lazyInitBusTransfer) {
				Hibernate.initialize(vo.getBusTransfer());
			}
			if (lazyInitBusCargos) {
				Hibernate.initialize(vo.getBusCargos());
			}
		}
	}


	public void setOrderno(Long val){
		setEQCondition("orderno", val);
	}
	
	public void setOrderno(Collection val){
		setINCondition("orderno", val);
	}
	
	public void setBillcodeEQ(String val){
		setEQCondition("billcode", val);
	}
	
	public void setBillcode(String val){
		setLIKECondition("billcode", val);
	}
	
	public void setBillcode(String[] val){
		setINCondition("billcode", val);
	}
	
	public void setOrdertype(String val){
		setEQCondition("ordertype", val);
	}
	
	public void setIslock(String val){
		setEQCondition("islock", val);
	}
	
	public void setBillstatus(String val){
		setEQCondition("billstatus", val);
	}
	
	public void setIsTransfer(String val){
		setEQCondition("istransfer", val);
	}
	
	public void setFromaddressname(String val){
		setLIKECondition("fromaddressname", val);
	}
	public void setToaddressname(String val){
		setLIKECondition("toaddressname", val);
	}
	public void setToaddressno(Long val){
		setEQCondition("toaddressno", val);
	}
	public void setTostorebillcode(String val){
		setLIKECondition("tostorebillcode", val);
	}
	
	public void setFetchPubCustomer(){
		setLeftJoinFetchs(" left join fetch this.pubCustomer pubCustomer ");
	}
	public void setCustomerno(Long val){
		setEQCondition("pubCustomer.customerno", val);
	}
	
	public void setCustomerno(Collection val){
		setINCondition("pubCustomer.customerno", val);
	}
	
	public void setCustomercode(String val){
		setLIKECondition("pubCustomer.customercode", val);
	}
	public void setCustomername(String val){
		setLIKECondition("pubCustomer.name", val);
	}
	
	public void setFetchBusTransfer(){
		setLeftJoinFetchs(" left jion fetch this.busTransfer busTransfer ");
	}
	
	public void setCreatorno(Long val){
		setEQCondition("creatorno", val);
	}
	
	public static BusOrder loadByNo(Long val){
		BusOrderQuery query = new BusOrderQuery();
		query.setOrderno(val);
		query.setLazy(true);
		query.setLazyInitPubCustomer(true);
		query.setLazyInitBusCargos(true);
		query.execute();
		
		if(query.getResults().size()!=1)
			return null;
		return (BusOrder)query.getResults().get(0);
	}
	
	public static List loadByNOs(List val){
		if(val==null || val.size()==0)
			return new ArrayList();
		BusOrderQuery query = new BusOrderQuery();
		query.setOrderno(val);
		query.execute();
		return query.getResults();
	}
}